import functools

n = int(input())
l = list()
for i in range(n):
    l.append(tuple(map(int, input().split())))


def cmp(a, b):
    if (a[1] < b[1]):
        return -1
    else:
        return 1


l = sorted(l, key=functools.cmp_to_key(cmp))
for i in l:
    print("%d %d" % i)
